<?php
$this->headScript()->appendFile('js/extjs-ux/filetree/Ext.ux.FileTreeMenu.js');
$this->headScript()->appendFile('js/extjs-ux/filetree/Ext.ux.FileTreePanel.js');
$this->headScript()->appendFile('js/extjs-ux/filetree/Ext.ux.form.BrowseButton.js');
$this->headScript()->appendFile('js/extjs-ux/filetree/Ext.ux.UploadPanel.js');
$this->headScript()->appendFile('js/extjs-ux/filetree/Ext.ux.FileUploader.js');

$this->headScript()
    ->appendFile('js/extjs-ecart/src/widgets/ImageBrowser.js')
    ->appendFile('js/extjs-ecart/src/widgets/FileTreePanel.js')
    ->appendFile('js/extjs-ecart/src/widgets/FileUploader.js')
    ->appendFile('js/extjs-ecart/src/widgets/form/ImageUploadField.js');

$this->headScript()
    ->appendFile('js/ecart/admin/catalog/index/category.js')
    ->appendFile('js/ecart/admin/catalog/index/category/grid.js')
    ->appendFile('js/ecart/admin/catalog/index/category/window.js')
    ->appendFile('js/ecart/admin/catalog/index/product.js')
    ->appendFile('js/ecart/admin/catalog/index/product/grid.js')
    ->appendFile('js/ecart/admin/catalog/index/panel.js')
    ->appendFile('js/ecart/admin/catalog/index/product/attributeWindow.js')
    ->appendFile('js/ecart/admin/catalog/index/product/modifierCombo.js')
    ->appendFile('js/ecart/admin/catalog/index/product/attributeDetails.js')
    ->appendFile('js/ecart/admin/catalog/index/product/propertyDetails.js')
    ->appendFile('js/ecart/admin/catalog/index/product/tabs/description.js')
    ->appendFile('js/ecart/admin/catalog/index/product/tabs/seo.js')
    ->appendFile('js/ecart/admin/catalog/index/product/tabs/inventory.js')
    ->appendFile('js/ecart/admin/catalog/index/product/tabs/price.js')
    ->appendFile('js/ecart/admin/catalog/index/product/tabs/image.js')
    ->appendFile('js/ecart/admin/catalog/index/product/tabs/property.js')
    ->appendFile('js/ecart/admin/catalog/index/product/tabs/attribute.js')
    ->appendFile('js/ecart/admin/catalog/index/product/tabs/variation.js')
    ->appendFile('js/ecart/admin/catalog/index/product/tabs/category.js')
    ->offsetSetFile(10000, 'js/ecart/admin/catalog/index/product/window.js');

// should be added automatically by modular admin layout system
if (in_array('Ecart_Tag', array_keys(Ecart::app()->getModules()))) {
    $this->headScript()->offsetSetFile(500, 'js/ecart/admin/tag/catalog_index/tabs/tag.js');
}
if (in_array('Ecart_Community', array_keys(Ecart::app()->getModules()))) {
    $this->headScript()->offsetSetFile(510, 'js/ecart/admin/community/catalog_index/tabs/review.js');
}

$this->setButtons(array(
    array(
        'title' => Ecart::translate('Ecart_Admin')->__('Back'),
        'onclick' => 'history.back()',
        'class' => 'alt-button'
    ),
    array(
        'title' => Ecart::translate('Ecart_Catalog')->__('Add Category'),
        'class' => 'button',
        'onclick' => 'Category.add(); return false;'
    ),
    array(
        'title' => Ecart::translate('Ecart_Catalog')->__('Add Product'),
        'class' => 'button',
        'onclick' => 'ProductGrid.add(); return false;'
    )
));
?>

<script type="text/javascript">

var manufacturers = [
<?php
$json = "{'id': null, 'name': 'None'.l()},\n";
foreach (Ecart_Collect_Manufacturer::collect() as $id => $name) :
    $json .= "{'id': $id, 'name': '$name'},\n";
endforeach;
echo substr($json, 0, -2);
?>
];

var taxClasses = [
<?php
$json = "{'id': null, 'name': 'None'.l()},\n";
foreach (Ecart_Collect_TaxClass::collect() as $id => $name) :
    $json .= "{'id': $id, 'name': '$name'},\n";
endforeach;
echo substr($json, 0, -2);
?>
];

<?php if ($this->productId) : ?>

Ext.onReady(function() {
    Product.load(<?php echo $this->productId?>);
});

<?php endif; ?>

</script>

<div id="ext-panel"></div>